package com.ruoyi.shop.service.impl;

import java.util.Date;
import java.util.List;

import com.ruoyi.shop.api.domain.CheShopImage;
import com.ruoyi.shop.mapper.CheShopImageMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.shop.mapper.CheShopMapper;

import com.ruoyi.shop.api.domain.CheShop;
import com.ruoyi.shop.service.ICheShopService;

/**
 * 门店管理Service业务层处理
 * 
 * @author ruoyi
 * @date 2024-12-31
 */
@Service
public class CheShopServiceImpl implements ICheShopService 
{
    @Autowired
    private CheShopMapper cheShopMapper;
    @Autowired
    private CheShopImageMapper cheShopImageMapper;

    /**
     * 查询门店管理
     * 
     * @param shopId 门店管理主键
     * @return 门店管理
     */
    @Override
    public CheShop selectCheShopByShopId(Long shopId)
    {
        
        CheShop cheShop = cheShopMapper.selectCheShopByShopId(shopId);
        if(cheShop != null){
            CheShopImage cheShopImage = new CheShopImage();
            cheShopImage.setShopId(shopId);
            List<CheShopImage> cheShopImages = cheShopImageMapper.selectCheShopImageList(cheShopImage);
            cheShop.setShopImages(cheShopImages);
            return cheShop;
        }else{
            return null;
        }
    }

    @Override
    public CheShop selectCheShopByPhone(String  perPhone)
    {
        CheShop cheShop = cheShopMapper.selectPhone(perPhone);
        return cheShop;
    }

    /**
     * 查询门店管理列表
     * 
     * @param cheShop 门店管理
     * @return 门店管理
     */
    @Override
    public List<CheShop> selectCheShopList(CheShop cheShop)
    {
        
        List<CheShop> cheShops = cheShopMapper.selectCheShopList(cheShop);
        for (CheShop item : cheShops){
            CheShopImage cheShopImage = new CheShopImage();
            cheShopImage.setShopId(item.getShopId());
            List<CheShopImage> cheShopImages = cheShopImageMapper.selectCheShopImageList(cheShopImage);
            item.setShopImages(cheShopImages);
        }
        return cheShops;
    }

    public List<CheShop> selectCheShopList1()
    {
        return cheShopMapper.selectCheShopList1();
    }

    /**
     * 新增门店管理
     * 
     * @param cheShop 门店管理
     * @return 结果
     */
    @Override
    public int insertCheShop(CheShop cheShop)
    {
        cheShop.setShopCreateTime(new Date());
        return cheShopMapper.insertCheShop(cheShop);
    }

    /**
     * 修改门店管理
     * 
     * @param cheShop 门店管理
     * @return 结果
     */
    @Override
    public int updateCheShop(CheShop cheShop)
    {
        return cheShopMapper.updateCheShop(cheShop);
    }

    /**
     * 批量删除门店管理
     * 
     * @param shopIds 需要删除的门店管理主键
     * @return 结果
     */
    @Override
    public int deleteCheShopByShopIds(Long[] shopIds)
    {
        return cheShopMapper.deleteCheShopByShopIds(shopIds);
    }

    /**
     * 删除门店管理信息
     * 
     * @param shopId 门店管理主键
     * @return 结果
     */
    @Override
    public int deleteCheShopByShopId(Long shopId)
    {
        return cheShopMapper.deleteCheShopByShopId(shopId);
    }

    @Override
    public List<CheShop> selectCheShopListByStar(CheShop cheShop) {
        return cheShopMapper.selectCheShopListByStar(cheShop);
    }
}
